<template>
  <p>{{time}}</p>
</template>

<script>
  import {formatDuring} from '../utils/index'
  export default {
    data () {
      return {
        time: ''
      }
    },
    props: {
      'setTime': String
    },
    methods: {
      test () {
        const result = this.setTime - new Date()
        const remainTime = formatDuring(result)
        this.time = remainTime
        const timeIndex = setTimeout(this.test, 1000)
        clearTimeout(timeIndex - 1)
      }
    },
    created () {
      // 调用应用实例的方法获取全局数据
      this.test()
    }
  }
</script>

<style>

</style>
